<template>
  <router-view></router-view>
</template>
<script>
  import setRouter from './utils/setRouter'
  export default {
    name: 'app',
    mounted () {
      this.setRouter()
    },
    methods: {
      setRouter () {
        if (sessionStorage.getItem('username')) {
          let indexRouter = JSON.parse(sessionStorage.getItem('indexRouter'))
          let routerData = JSON.parse(sessionStorage.getItem('router'))
          this.$store.dispatch('setIndexRouterData', indexRouter)
          this.$store.dispatch('setModuleRouterData', routerData)
          this.$router.addRoutes(setRouter.setIndex(indexRouter))
          this.$router.addRoutes(setRouter.setModule(routerData))
        } else {
          sessionStorage.removeItem('indexRouter')
          sessionStorage.removeItem('router')
          sessionStorage.removeItem('username')
          this.$router.push('/login')
        }
      }
    }
  }
</script>
